using DocumentFormat.OpenXml.Drawing.Diagrams;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Channels;
using Cmc.RabbitMQ;
using Cmc.RabbitMQ.Base;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigHelper cf = new ConfigHelper();
            var configs = cf.Get<ConfigTemp>("mqconfig", "", true) ?? new ConfigTemp(){mqconfig = new List<ConnectConfig>()};

            IConnectionFactory connectionFactory = new DefaultConnectionFactory();

            var con = connectionFactory.GetConnection("xy", configs.mqconfig);



            con.Consume(new Consumer()
            {
                ConsumerID = "testconsumer", 
                QueueName = "test",
                ConsumEventHandler = (sender, eventArgs) =>
                {

                    Console.WriteLine("----------------------------------------------------");

                }
            });


            int i=0;
            do
            {
                con.PublishByRoutingKey("test1", i++);


                con.PublishByRoutingKey("test2", i++);
                con.PublishByRoutingKey("test3", i++);

                Thread.Sleep(3000);
            } while (true);


            //string queneName = "test";

            //string[] routingKey=new string[]{"test1","test2","test3"};

            //List<ConnectConfig> list =new List<ConnectConfig>();

            //ConnectConfig cc=new ConnectConfig()
            //{
            //    HostName = "1",
            //    HostAddress = "8.131.84.6",
            //    Port = 5672,
            //    UserName = "admin",
            //    Password = "rabbitmq_123456"
            //};

            //cc.ExchangeConfigs=new List<ExchangeConfig>();
            //cc.ExchangeConfigs.Add(new ExchangeConfig()
            //{
            //    ExchangeName = "ymqg",
            //    ExchangeType = ExchangeType.fanout,
            //    IsDurable = true
            //});



            //cc.QueueConfigs=new List<QueueConfig>();
            //cc.QueueConfigs.Add(new QueueConfig()
            //{
            //     ExchangeName = "ymqg",
            //     IsDurable = true,
            //     QueueName = queneName,
            //     RoutingKey = routingKey.ToList()
            //});


            //list.Add(cc);

            //Console.WriteLine(JsonConvert.SerializeObject(list));

            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }
    }
}
